作業 4 題目
參考答案 :
token_file="/var/run/secrets/kubernetes.io/serviceaccount/token"
ca_crt_file="/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
token=`cat $token_file`
echo "kubectl in $1..."
echo "api server in $2..."
$1 config set-cluster cfc --server=$2 --certificate-authority=$ca_crt_file ;
$1 config set-context cfc --cluster=cfc ;
$1 config set-credentials user --token=$token ;
$1 config set-context cfc --user=user ;
$1 config use-context cfc ;
使用方式
sh [腳本名稱] [kubectl程式位址] [API Server 網址] ;
sh [腳本名稱] /kubectl https://10.96.0.1 ;